﻿using System;
using weka.core;
using weka.core.converters;
using java.io;

namespace OMC.Classification
{
    /// <summary>
    /// an object of this class can manage all the parts of loading data from a file
    /// </summary>
    /// <remarks>
    /// Copyright 2012 Stefan Lütolf
    /// </remarks>
    class DataLoader
    {
        private ArffLoader TheLoader;
        private Instances TheRawData;
        private String TheFilePath;

        /// <summary>
        /// the constructor to generate an object
        /// </summary>
        /// <param name="inFilePath">
        /// the file Path inkl. filename of the arff data file
        /// for example: -> C:\Program Files\Microsoft Office\Office14\BAMailClassData\
        /// if you chose the folowing string as inFilePath: "./BAMailClassData/ARFF/data.arff"
        /// </param>
        public DataLoader(String inFilePath)
        {
            this.TheFilePath = inFilePath;
        }

        /// <summary>
        /// to load the arff data from a file
        /// </summary>
        /// <returns>
        /// the returned data are from type of Instances
        /// </returns>
        public Instances load()
        {
            TheLoader = new ArffLoader();
            TheRawData = null;
            try
            {
                TheLoader.setSource(new File(TheFilePath));
                TheRawData = TheLoader.getDataSet();
                TheRawData.setClassIndex(TheRawData.numAttributes() - 1);
            }
            catch (Exception e)
            {
                e.StackTrace.ToString();
            }
            return TheRawData;
        }
    }
}